

text = input('Please enter electronic configuration\n')

ato_ls = [ i for i in text if i in 'spdf' ]
l_dict = {
    's':0,
    'p':1,
    'd':2,
    'f':3,
}
s = [ 1/2 for i in ato_ls ]
l = [ l_dict[i] for i in ato_ls ]
l_dict_re = {}
for k,v in l_dict.items():
    l_dict_re[v] = k.upper()


coupling_S = [ i for i in range( int(abs(s[0]-s[1])), int(sum(s))+1 ) ]

coupling_L = [ i for i in range( int(abs(l[0]-l[1])), int(sum(l))+1 ) ]

print('\nL-S coupling')
print('S = {}'.format(coupling_S))
print('L = {}\n'.format(coupling_L))
for ss in coupling_S:
    for ll in reversed(coupling_L):
        coupling_J = [ i for i in range( abs(ss-ll), ss+ll+1) ]
        coupling_J.reverse()
        print('S = {}\tL = {}\tJ = {}\t{}{}{}'.format(ss,ll,coupling_J,2*ss+1,l_dict_re[ll],str(coupling_J).strip('[]')))

print('\nj-j coupling')

jj1 = [abs(l[0]-s[0]),abs(l[0]+s[0])]
jj2 = [abs(l[1]-s[1]),abs(l[1]+s[1])]

for j1 in jj1:
    for j2 in jj2:
        J = [i for i in range(int(abs(j1-j2)) ,int(j1+j2)+1)]
        J.reverse()
        print('j1 = {0}\tj2 = {1}\tJ = {2}\t({0},{1}){3}'.format(j1,j2,J,str(J).strip('[]')))

